'''
@project:Tinyshop_t174
@auther:lihanliang
@file:broswersetting1.py
@date:2022/11/7 19:04
@dasc:
'''
import time
from selenium import webdriver
import unittest
from selenium.webdriver import ActionChains
from Tinyshop_t174.conf.config1 import config1
from Tinyshop_t174.elements.tinyshop_elements import *


class Broswersetting1(unittest.TestCase):
    def setUp(self) -> None:
        if config1.BroswerName=='chrome':
            # print(config1.BroswerName)
            self.driver=webdriver.Chrome()
        elif config1.BroswerName=='firefox':
            self.driver=webdriver.Firefox
        elif config1.BroswerName=='edge':
            self.driver=webdriver.Edge
        self.driver.get('http://%s' % config1.HOST)
        self.driver.maximize_window()
        time.sleep(2)

    def tearDown(self) -> None:
        self.driver.quit()
        time.sleep(2)

    def tinyshop_dl(self,account,password):
        self.driver.find_element(input_zh['element_locator'],input_zh['element_value']).send_keys(account)
        self.driver.find_element(input_mm['element_locator'],input_mm['element_value']).send_keys(password)
        self.driver.find_element(click_dl['element_locator'],click_dl['element_value']).click()

    def tinyshop_gw(self,keyword,select):
        self.driver.find_element(input_kw['element_locator'],input_kw['element_value']).send_keys(keyword)
        self.driver.find_element(click_ss['element_locator'],click_ss['element_value']).click()
        ActionChains(self.driver).release(self.driver.find_element(action_sp['element_locator'],action_sp['element_value'])).perform()
        self.driver.find_element(click_pd['element_locator'],click_pd['element_value']).click()
        self.driver.find_element(click_k1['element_locator'],click_k1['element_value']).click()
        self.driver.find_element(click_k2['element_locator'],click_k2['element_value']).click()
        if select=='buy-now':
            self.driver.find_element(click_bn['element_locator'],click_bn['element_value']).click()
        else:
            self.driver.find_element(click_ct['element_locator'],click_ct['element_value']).click()
            ActionChains(self.driver).release(self.driver.find_element(action_sc['element_locator'],action_sc['element_value'])).perform()
            self.driver.find_element(click_js1['element_locator'], click_js1['element_value']).click()
        self.driver.find_element(click_js2['element_locator'],click_js2['element_value']).click()
        self.driver.find_element(click_tj['element_locator'],click_tj['element_value']).click()
        self.driver.find_element(click_zf['element_locator'],click_zf['element_value']).click()
        handles=self.driver.window_handles
        self.driver.switch_to.window(handles[1])

    def tinyshop_dz(self,zip,addr,accept_name,mobile,phone):
        ActionChains(self.driver).release(self.driver.find_element(action_center['element_locator'],action_center['element_value'])).perform()
        self.driver.find_element(click_sh['element_locator'],click_sh['element_value']).click()
        self.driver.find_element(click_ao['element_locator'],click_ao['element_value']).click()
        iframe=self.driver.find_element(i_frame['element_locator'],i_frame['element_value'])
        self.driver.switch_to.frame(iframe)
        self.driver.find_element(click_zip1['element_locator'],click_zip1['element_value']).click()
        self.driver.find_element(click_zip2['element_locator'],click_zip2['element_value']).click()
        self.driver.find_element(click_zip3['element_locator'],click_zip3['element_value']).click()
        self.driver.find_element(input_zip['element_locator'],input_zip['element_value']).send_keys(zip)
        self.driver.find_element(input_addr['element_locator'],input_addr['element_value']).send_keys(addr)
        self.driver.find_element(input_an['element_locator'],input_an['element_value']).send_keys(accept_name)
        self.driver.find_element(input_mobile['element_locator'],input_mobile['element_value']).send_keys(mobile)
        self.driver.find_element(input_phone['element_locator'],input_phone['element_value']).send_keys(phone)
        self.driver.find_element(click_dz['element_locator'],click_dz['element_value']).click()



class Broswersetting2(unittest.TestCase):
    def setUp(self) -> None:
        if config1.BroswerName == 'chrome':
            # print(config1.BroswerName)
            self.driver = webdriver.Chrome()
        elif config1.BroswerName == 'firefox':
            self.driver = webdriver.Firefox
        elif config1.BroswerName == 'edge':
            self.driver = webdriver.Edge
        self.driver.get('http://%s' % config1.HOST1)
        self.driver.maximize_window()
        time.sleep(2)

    def tearDown(self) -> None:
        self.driver.quit()
        time.sleep(2)


    def tinyshop_ht(self,admin,password,verifyCode='aaaa'):
        self.driver.find_element(input_yh['element_locator'],input_yh['element_value']).send_keys(admin)
        self.driver.find_element(input_mmm['element_locator'],input_mmm['element_value']).send_keys(password)
        self.driver.find_element(input_yz['element_locator'],input_yz['element_value']).send_keys(verifyCode)
        self.driver.find_element(click_dll['element_locator'],click_dll['element_value']).click()

    def tinyshop_tg(self,title,max_num,quota_num,price,start_time,end_time):
        self.driver.find_element(click_yx['element_locator'],click_yx['element_value']).click()
        self.driver.find_element(click_qg['element_locator'],click_qg['element_value']).click()
        self.driver.find_element(click_cxtj['element_locator'],click_cxtj['element_value']).click()
        self.driver.find_element(input_name['element_locator'],input_name['element_value']).send_keys(title)
        self.driver.find_element(click_xzsp['element_locator'],click_xzsp['element_value']).click()
        i_frame=self.driver.find_element(i_framee['element_locator'],i_framee['element_value'])
        self.driver.switch_to.frame(i_frame)
        self.driver.find_element(click_spxh['element_locator'],click_spxh['element_value']).click()
        self.driver.find_element(click_xd['element_locator'],click_xd['element_value']).click()
        self.driver.find_element(input_qgsl['element_locator'],input_qgsl['element_value']).send_keys(max_num)
        self.driver.find_element(input_xgsl['element_locator'],input_xgsl['element_value']).send_keys(quota_num)
        self.driver.find_element(input_xgjg['element_locator'],input_xgjg['element_value']).send_keys(price)
        self.driver.find_element(input_start['element_locator'],input_start['element_value']).send_keys(start_time)
        self.driver.find_element(input_end['element_locator'],input_end['element_value']).send_keys(end_time)
        self.driver.find_element(click_qgtj['element_locator'],click_qgtj['element_value']).click()

    def tinyshop_tj(self,name,goods_no,store_nums,sell_price,market_price):
        self.driver.find_element(click_sp['element_locator'],click_sp['element_value']).click()
        self.driver.find_element(click_sptj['element_locator'],click_sptj['element_value']).click()
        self.driver.find_element(click_fl['element_locator'],click_fl['element_value']).click()
        self.driver.find_element(click_flxz['element_locator'],click_flxz['element_value']).click()
        self.driver.find_element(click_spmc['element_locator'],click_spmc['element_value']).send_keys(name)
        self.driver.find_element(click_spbh['element_locator'],click_spbh['element_value']).send_keys(goods_no)
        self.driver.find_element(click_tjtp['element_locator'],click_tjtp['element_value']).click()
        i_frameee=self.driver.find_element(click_tp['element_locator'],click_tp['element_value'])
        self.driver.switch_to.frame(i_frameee)
        self.driver.find_element(click_tktp['element_locator'],click_tktp['element_value']).click()
        self.driver.find_element(click_xztp['element_locator'],click_xztp['element_value']).click()
        self.driver.find_element(click_bctp['element_locator'],click_bctp['element_value']).click()
        self.driver.find_element(click_kc['element_locator'],click_kc['element_value']).send_keys(store_nums)
        self.driver.find_element(click_lsj['element_locator'],click_lsj['element_value']).send_keys(sell_price)
        self.driver.find_element(click_scj['element_locator'],click_scj['element_value']).send_keys(market_price)
        self.driver.find_element(click_tjtj['element_locator'],click_tjtj['element_value']).click()

    def tinyshop_kh(self,name,password,email,real_name,birthday):
        self.driver.find_element(click_kh['element_locator'],click_kh['element_value']).click()
        self.driver.find_element(click_khtj['element_locator'],click_khtj['element_value']).click()
        self.driver.find_element(input_yhm['element_locator'],input_yhm['element_value']).send_keys(name)
        self.driver.find_element(input_pw['element_locator'],input_pw['element_value']).send_keys(password)
        self.driver.find_element(input_repw['element_locator'],input_repw['element_value']).send_keys(password)
        self.driver.find_element(input_email['element_locator'],input_email['element_value']).send_keys(email)
        self.driver.find_element(input_rn['element_locator'],input_rn['element_value']).send_keys(real_name)
        self.driver.find_element(input_bd['element_locator'],input_bd['element_value']).send_keys(birthday)
        self.driver.find_element(click_zip11['element_locator'],click_zip11['element_value']).click()
        self.driver.find_element(click_zip22['element_locator'],click_zip22['element_value']).click()
        self.driver.find_element(click_zip33['element_locator'],click_zip33['element_value']).click()
        self.driver.find_element(click_hytj['element_locator'],click_hytj['element_value']).click()


